<?php


namespace app\common\business;

use app\service\MongoHelper;
use app\common\lib\SnowflakeRedis;

/**
 * Task异步任务处理逻辑层
 */
class SwooleTask {

    /**
     * 发送验证码
     * @param $data
     * @return string
     */
    public function send($data) {
        $data = is_array($data) ? json_encode($data) : $data;
        debugLog($data, 'task');
        return 'send-ok';
    }

    /**
     * 发送邮件
     * @param $data
     * @return string
     */
    public function mail($data) {
        $data = is_array($data) ? json_encode($data) : $data;
        debugLog($data, 'task');
        return 'mail-ok';
    }

    /**
     * @param $data
     * @return array
     */
    public function mongoDb($data) {
        /*$result = MongoHelper::getInstance()->namespaces("test.sites")
            ->whereIn("name", ["u1", "u5"])->order("age", MongoHelper::SORT_DESC)->field("name,age")
            ->find();*/

        $filter = ['x' => ['$gt' => 1]];
        $result = \app\service\MongoDb::getInstance()->query('sites', $filter);

        $instance = SnowflakeRedis::getInstance();
        $instance->setWorkerId(2)->setServerId(1);
        //$result = $instance->nextId();
        $result2 = $result;
        return $result;
    }
}